package com.lening.community.controller;

import com.lening.common.base.BaseController;
import com.lening.common.util.OssUtil;
import com.lening.common.web.Result;
import com.lening.community.dto.CommunityDto;
import com.lening.community.pojo.Community;
import com.lening.community.service.BuildingService;
import com.lening.community.service.CommunityService;
import com.lening.community.service.impl.Comm;
import com.lening.community.vo.TableVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.reactive.function.client.WebClient;

import java.util.List;

/**
 * @ToDo:
 * @Author：潘万法
 * @date: 2024/6/1 11:22
 */
@Slf4j
@RestController
@RequestMapping("community")
public class CommunityController extends BaseController<Community, CommunityDto, CommunityService> {
    @Autowired(required = false)
    private WebClient webClient;
    @Autowired(required = false)
    private CommunityService communityService;
    private BuildingService buildingService;
    @Autowired(required = false)
    private Environment environment;

    @Autowired(required = false)
    private Comm comm;

//    @GetMapping("pages")
//    public Page<?> pages(CommunityDto communityDto) {
//        Page<?> page = communityService.page(communityDto);
//        return page;
//    }

    @GetMapping("ok")
    public String ok() {
        log.info("ok方法");
        try {
            Thread.sleep(4000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        return "ok,server.port: " + environment.getProperty("server.port");
    }

    @GetMapping("get")
    public List<TableVo> get() {
        return comm.execute();
    }

    /**
     * 四级联动
     *
     * @return
     */
    @GetMapping("getAll")
    public List<TableVo> getAll() {
        return comm.getAll();
    }

    @PostMapping("UpLoad")
    public Result<?> upload(MultipartFile multipartFile) {
        String s = OssUtil.uploadFileAvatar(multipartFile);
        return Result.ok(s);
    }

    /**
     * 查询社区数量
     */
    @GetMapping("getCount")
    public int getCount() {

        return communityService.getCount();
    }
}
